<template>

    <div class="">
      <el-card>
       <el-form :inline="true">
        <el-form-item label="关键字">
          <el-input style="200px" v-model="params.keyword"></el-input>
        </el-form-item>
        <el-form-item class="right">
          <el-button @click="qinchu">清除</el-button>
          <el-button type="primary" @click="sousuo">搜索</el-button>
        </el-form-item>
       </el-form>
       <el-alert
          type="info"
          class="alert"
          :closable="false"
          show-icon
        >数据一共{{this.total}}条</el-alert>

        <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号"
        >
      </el-table-column>
      <el-table-column
        prop="questionType"
        label="题型"
        >
      <template v-slot="props">
        {{questionType[props.row.questionType]}}
      </template>
      </el-table-column>

      <el-table-column
        prop="questionIDs.number"
        label="题目编号">
        <template v-slot="props">
          <a href="#" :key="idx" v-for="(item,idx) in props.row.questionIDs">{{item.number}}</a>
        </template>
      </el-table-column>
       <el-table-column
        prop="addTime"
        label="录入时间">
      </el-table-column>
       <el-table-column
        prop="totalSeconds"
        label="答题时间(s)">
      </el-table-column>
       <el-table-column
        prop="accuracyRate"
        label="正确率(%)">
      </el-table-column>
       <el-table-column
        prop="userName"
        label="录入人">
      </el-table-column>
       <el-table-column label="操作">
         <template v-slot="props">

        <el-button type="danger" icon="el-icon-delete" circle @click="del(props.row.id)">
        </el-button>

         </template>

      </el-table-column>
    </el-table>
    <div class="fenye">
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-size="params.pagesize"
      layout="sizes, prev, pager, next"
      :total="total"
      :current-page="params.page"
      :page-sizes="[5, 10, 20]"
      >
    </el-pagination>
    </div>
      </el-card>
    </div>
</template>

<script>
import { randoms, removeRandoms } from '@/api/hmmm/questions.js'
export default {
  name: '',
  components: {

  },
  props: {

  },
  data () {
    return {
      tableData: [],

      params: {
        page: 1,
        pagesize: 10,
        keyword: null
      },
      total: null,
      questionType: {
        1: '简答',
        2: '多选',
        3: '单选'
      },

      alertText: ''

    }
  },
  created () {
    this.randomsList()
  },
  methods: {
    async randomsList () {
      console.log({
        page: this.params.page,
        pagesize: this.params.pagesize
      })
      const { data } = await randoms(this.params)
      console.log(data)
      this.tableData = data.items
      this.total = data.counts
    },
    async del (id) {
      // console.log(id)
      await removeRandoms({ id })
      this.$message.success('删除成功')
      this.randomsList()
    },
    qinchu () {
      this.params.keyword = ''
      this.randomsList()
    },
    handleSizeChange (val) {
      // console.log(val)
      this.params.pagesize = val
      this.randomsList()
    },
    handleCurrentChange (val) {
      // console.log(val)
      this.params.page = val
      this.randomsList()
    },
    sousuo () {
      this.params.page = 1
      this.randomsList()
    }
  }
}
</script>

<style  scoped>
.fenye{
  margin-top: 25px;
}
.right{
  float: right;
}
/* .fenye input{
  position: relative;
  top: 10px;
} */
</style>
